#!/usr/bin/env python
# encoding: utf-8
# @Time : 2020/4/15 23:34 
# @Author : 能量咖啡豆 
# @File : datatype.py 
# @desc : datatype.py 


class Solution:
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        temp = "1"
        for i in range(1,n):
            temp = self.genNext(temp)
        return temp

    def genNext(self, curstr):
        curl = list(curstr)
        ccount = 0
        temp0 = curl[0]
        rl = []
        for i in range(len(curl)):
            temp1 = curl[i]
            if temp1 == temp0:
                ccount += 1
            else:
                rl.append(str(ccount))
                rl.append(temp0)
                temp0 = temp1
                ccount = 1
        if ccount != 0:
            rl.append(str(ccount))
            rl.append(temp0)
        if len(rl) == 0:
            rl.append(str(ccount))
            rl.append(temp0)
        return ''.join(rl)

def romanToInt(s):
    """
    :type s: str
    :rtype: int
    """
    numDict = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000, "IV": 4, "IX": 9, "XL": 40, "XC": 90,
               "CD": 400, "CM": 900}
    num = 0
    bflag = False
    for i in range(len(s)):
        if bflag:
            continue
        if i+1 < len(s):
            ss = s[i]+s[i+1]
            if ss in numDict.keys():
                num += numDict[ss]
                bflag = True
            else:
                num += s[i]
                bflag = False
    return num

if __name__ ==  '__main__':
    ss = Solution()
    print(ss.countAndSay(3))
